﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MyMaster.Master" AutoEventWireup="true"
    CodeBehind="ContentMangeAddChildMenu.aspx.cs" Inherits="FashionMural.Admin.ContentMangeAddChildMenu" %>

<asp:Content ID="Content1" ContentPlaceHolderID="LeftMenu" runat="server">
    <%--    <asp:TreeView ID="BarMenu" runat="server">
    </asp:TreeView>--%>
    <script type="text/javascript">
        $().ready(function () {
            DynamicBuildPageTreeView("pageTreeDiv");

            var dyflag = true;
            $("div.leftMenuTitle").click(function () {
                if (dyflag) {
                    $(this).next(".leftMenu").hide();
                    dyflag = false;
                } else {
                    $(this).next(".leftMenu").show();
                    dyflag = true;
                }
            });
        });
    </script>
    <div id="pageTreeDiv">
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MidContent" runat="server">
    <script type="text/javascript" src="Xheditor/xheditor-1.1.13-zh-cn.min.js"></script>
    <script type="text/javascript">
        function deletePage(id) {
            $.ajax({
                async: false,
                type: "GET",
                url: "/jsserver/page/delete.aspx",
                data: { id: id },
                success: function (data) {
                    alert('删除成功！');
                    location.reload();
                }
            });
        }

        function savewebsiteinfofun(id) {
            $.ajax({
                type: "POST",
                async: false,
                url: "/jsserver/page/update.aspx",
                data: { id: id, name: $("#inputwebsitename").val() },
                success: function (data) {
                    if (data == "True") {
                        alert('保存成功！');
                        $("#labelwebsitename")[0].innerText = $("#inputwebsitename").val();
                        hidewebsitename();
                    } else {
                        alert('保存失败，请重新修改！');
                    }
                },
                error: function () {
                    alert('保存失败，请重新修改！');
                }
            });
        }

        function editPage(id) {
            window.location.href = "/ContentManageChildMenuEdit.aspx?nodeid="+id;
        }

        function showwebsitename() {
            $("#labelwebsitename").hide();
            $("#inputwebsitename").show();
        }

        function hidewebsitename() {
            $("#labelwebsitename").show();
            $("#inputwebsitename").hide();
        }

        //init addchild jump div
        function initAddChildJumpDiv() {
            var types = GetMenuTypes();
            for (i = 0; i < types.length; i++) {
                $("#childpagetype").append("<option value=" + types[i].Id + ">" + types[i].PageTypeName + "</option>");
            }
            $('#addchildjumpdiv').show();
        }

        function addChildPage() {
            var title = $("#childwebsitename").val();
            var parentpageid = <%=CurrentPage.Id %>;
            var pageTypeid = $("#childpagetype").val();
            var pagedescribe = $("#pagedescribe")[0].innerText;
            var ppath = $("#pagesmallphopath").val();
            var phocontent = $("#pagesmallpho").xheditor().getSource();
            $.ajax({
                type: "POST",
                async: true,
                url: "/jsserver/page/add.aspx",
                data: { title:title,parentId:parentpageid,pageTypeId:pageTypeid,pagedes:pagedescribe,phopath:ppath,phocontent:phocontent },
                success: function (data) {
                    if (data > 0) {
                        alert('保存成功！');
                        $("#addchildjumpdiv").hide();
                        location.reload();
                    } else {
                        alert('保存失败，请重新修改！');
                    }
                },
                error: function () {
                    alert('保存失败，请重新修改！');
                }
            });
        }

        function UploadImageCallBackFun(msg){
            $("#pagesmallphopath").val(msg);
        }

        $().ready(function () {
            $("#contentedit").show();
            $("#childlist").hide();
            $("#aforcontentedit").click(function () {
                $("#contentedit").show();
                $("#childlist").hide();
            });
            $("#aforchildlist").click(function () {
                $("#contentedit").hide();
                $("#childlist").show();
            });

            //websitename show or hide
            $("#labelwebsitename").show();
            $("#inputwebsitename").hide();
            $("#editwebinfo").click(function () {
                showwebsitename();
            });
            $("#canceledit").click(function () {
                hidewebsitename();
            });

            //init jump div
            $("#addchildjumpdiv").hide();

            $("#pagesmallpho").xheditor({
                tools:'Img',
                width: 200,
                height: 20,
                upImgUrl:"/upload.aspx?fileflag=imagelist",//?fileflag=sigle
                upImgExt:".jpg",
                onUpload:UploadImageCallBackFun
            });
            
        });
    </script>
    <div id="mainMenu">
        <ul>
            <li><a id="aforcontentedit" href="#">内容编辑</a></li><li><a id="aforchildlist" href="#">
                子栏目列表</a></li></ul>
    </div>
    <div id="main">
        <asp:Label ID="Msg" runat="server" Text="" CssClass="msg" Visible="False"></asp:Label>
        <table class="mainTable" id="contentedit">
            <tr style="background-color: #D7D7D7;">
                <th colspan="2">
                    <%=CurrentPage.PageName+"配置" %>
                </th>
            </tr>
            <tr>
                <td style="width: 20%; text-align: right;">
                    网站名称:
                </td>
                <td>
                    <label id="labelwebsitename">
                        <%=CurrentPage.PageName %></label>
                    <input id="inputwebsitename" type="text" value="<%=CurrentPage.PageName %>" />&nbsp;
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">
                    页面类型:
                </td>
                <td>
                    <%--<%foreach (Omes.Model.PageType pt in GetPageTypes(CurrentPage.Id))
                      {%><%=pt.PageTypeName %><br />
                    <%} %>--%>
                    <%=GetPageType(CurrentPage.PageTypeId).PageTypeName %>&nbsp;
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">
                    父页面:
                </td>
                <td>
                    <%=GetPage(CurrentPage.ParentId).PageName %>&nbsp;
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">
                    是否显示:
                </td>
                <td>
                    <%=CurrentPage.ShowOnNar %>&nbsp;
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">
                    是否新窗口打开:
                </td>
                <td>
                    <%=CurrentPage.NewWindow %>&nbsp;
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">
                    &nbsp;
                </td>
                <td>
                    <%--                    <asp:Button ID="savewebsiteinfo" runat="server" BackColor="#D7D7D7" CssClass="btn"
                        Text="保存信息" />
                    <asp:Button ID="canceledit" runat="server" BackColor="#D7D7D7" CssClass="btn" Text="取消" />--%>
                    <input id="editwebinfo" type="button" style="background-color: #D7D7D7; border: 1px solid Balck;
                        cursor: pointer;" value="编辑" />
                    <input id="savewebsiteinfo" type="button" style="background-color: #D7D7D7; border: 1px solid Balck;
                        cursor: pointer;" value="保存" onclick="savewebsiteinfofun(<%=CurrentPage.Id %>)" />
                    <input id="canceledit" type="button" style="background-color: #D7D7D7; border: 1px solid Balck;
                        cursor: pointer;" value="取消" />
                </td>
            </tr>
        </table>
        <table class="mainTable" id="childlist">
            <tr style="background-color: #D7D7D7;" id="addchildbar">
                <th>
                    栏目名称
                </th>
                <th>
                    页面类型
                </th>
                <th>
                    父页面
                </th>
                <th>
                    是否显示
                </th>
                <th>
                    是否新窗口打开
                </th>
                <th>
                    操作
                </th>
            </tr>
            <%foreach (Omes.Model.Page currentPage in CurrentPageChilds)
              {%>
            <tr id="childrenpagelist<%=currentPage.Id %>">
                <td>
                    <%=currentPage.PageName %>&nbsp;
                </td>
                <td>
                    <%=GetPageType(currentPage.PageTypeId).PageTypeName %>&nbsp;
                </td>
                <td>
                    <%=GetPage(currentPage.ParentId).PageName %>&nbsp;
                </td>
                <td>
                    <%=currentPage.ShowOnNar %>&nbsp;
                </td>
                <td>
                    <%=currentPage.NewWindow %>&nbsp;
                </td>
                <td>
                    <input type="button" id="editlabel<%=currentPage.Id %>" pid="<%=currentPage.Id %>"
                        onclick="editPage(<%=currentPage.Id %>)" value="编辑" style="background-color: #D7D7D7;
                        border: 1px solid Balck; cursor: pointer;" />
                    <input type="button" id="deletepageinfo<%=currentPage.Id %>" pid="<%=currentPage.Id %>"
                        onclick="deletePage(<%=currentPage.Id %>)" value="删除" style="background-color: #D7D7D7;
                        border: 1px solid Balck; cursor: pointer;" />
                </td>
            </tr>
            <%} %>
            <tr>
                <td colspan="6">
                    <input id="addchildpage" type="button" style="background-color: #D7D7D7; cursor: pointer;"
                        value="添加子栏目" onclick="initAddChildJumpDiv();" />
                </td>
            </tr>
        </table>
        <div class="jumpdiv-back" id="addchildjumpdiv">
            <div class="jumpdiv-forward">
                <table class="mainTable" id="addchildtable">
                    <tr>
                        <td style="width: 20%; text-align: right;">
                            网站名称:
                        </td>
                        <td>
                            <input id="childwebsitename" type="text" />
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">
                            页面小图:
                        </td>
                        <td>
                            <input type="hidden" id="pagesmallphopath" />
                            <textarea id="pagesmallpho"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">
                            页面类型:
                        </td>
                        <td>
                            <select id="childpagetype">
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">
                            父页面:
                        </td>
                        <td>
                            <%=CurrentPage.PageName %>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">
                            页面描述:
                        </td>
                        <td>
                        <textarea id="pagedescribe" style="height:200px;width:100%;"><%=CurrentPage.PageDescribe %></textarea>
                        </td>
                    </tr>                    
                    <tr>
                        <td colspan="2">
                            <input id="addchildpagebtn" type="button" style="background-color: #D7D7D7; cursor: pointer;
                                margin-right: 5px;" value="添加" onclick="addChildPage()" />&nbsp;<input id="canceladdchildpagebtn"
                                    type="button" style="background-color: #D7D7D7; cursor: pointer;" value="取消"
                                    onclick="$('#addchildjumpdiv').hide();" />
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</asp:Content>
